<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:composition template="../Master/adminMaster.xhtml">
            <ui:define name="page-content">
                <!--                <div id="page-header">
                                    <h1>Articles</h1>
                                </div>-->

                <section class="grid_12" id="dashtabs">
                    <div class="box-header">
                        Departments Manager
                        <ul class="controls"></ul>
                    </div>
                    <div id="dashtabs-pages" class="box-content no-padding">
                        <f:view>
                            <h:form id="form" prependId="false">

                                <p:growl id="messages" showDetail="true"/>

                                <p:dataTable var="item" value="#{departmentMBean.departments}" id="departmentDataTable" editable="true"
                                             style="width: 100% !important;" styleClass="table no-border"
                                             paginator="true" rows="10" rowsPerPageTemplate="5,10,15"
                                             paginatorPosition="bottom"
                                             emptyMessage="No department found with given criteria" 
                                             filteredValue="#{departmentMBean.filteredDepartments}"
                                             widgetVar="departmentsTable" rowKey="#{item.departmentID}">

                                    <p:ajax event="rowEdit" listener="#{departmentMBean.editDepartment}" update=":form:messages" />
                                    <p:ajax event="rowEditCancel" listener="#{departmentMBean.cancelEditDepartment}" update=":form:messages" />

                                    <f:facet name="header">  
                                        <p:outputPanel style="float: right;">  
                                            <h:outputText value="Search all fields:"/>  
                                            <p:inputText id="globalFilter" onkeyup="articlesTable.filter()" style="width:150px" />  
                                        </p:outputPanel>  
                                    </f:facet>

                                    <p:column headerText="Name" filterBy="#{item.departmentName}" 
                                              filterMatchMode="contains" sortBy="#{item.departmentName}">
                                        <p:cellEditor>
                                            <f:facet name="output">
                                                <h:outputText value="#{item.departmentName}" />
                                            </f:facet>
                                            <f:facet name="input">
                                                <p:inputText value="#{departmentMBean.departmentName}" style="width:70%">
                                                    #{item.departmentName}
                                                </p:inputText>
                                            </f:facet>
                                        </p:cellEditor>
                                    </p:column>

                                    <p:column headerText="Options" style="width:100px !important;">
                                        <p:rowEditor />
                                        <h:panelGroup rendered="#{login.customer.membersRole == 2}">
                                            <p:commandLink id="showDialogButton" onclick="confirmation.show()"
                                                           title="Remove"
                                                           update=":form:display">
                                                <p:graphicImage value="../CSS/images/cross_circle.png" alt=""></p:graphicImage>
                                                <f:setPropertyActionListener value="#{item}" 
                                                                             target="#{departmentMBean.selectedDepartment}" />
                                            </p:commandLink> 
                                        </h:panelGroup>
                                    </p:column>

                                </p:dataTable>

                                <p:confirmDialog id="confirmDialog" message="Are you sure about remove this department?"  
                                                 header="Initiating destroy process" 
                                                 severity="alert" widgetVar="confirmation">  
                                    <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">  

                                        <p:commandButton id="confirm" value="Yes Sure" update=":form:messages,:form:departmentDataTable" 
                                                         oncomplete="confirmation.hide()"  
                                                         actionListener="#{departmentMBean.removeDepartment}">

                                        </p:commandButton>
                                        <p:commandButton id="decline" value="Not Yet" onclick="confirmation.hide()" type="button" />

                                    </h:panelGrid>  
                                </p:confirmDialog>

                            </h:form>
                        </f:view>
                    </div>

                </section>
                <br class="cl" />
            </ui:define>
        </ui:composition>
    </h:body>
</html>

